package network

import extensions.asRequestBody
import extensions.toInputStream
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.flowOf
import network.repositories.uploadService
import okhttp3.MultipartBody
import utils.ImageUtils
import java.awt.Image
import java.awt.image.BufferedImage

object NetworkUtils {
    suspend fun uploadImages(images: BufferedImage, fileName: String): Boolean {
        val result = uploadService().uploadImage(
            listOf(
                MultipartBody.Part.createFormData(
                    "files",
                    fileName,
                    ImageUtils.compressImage(images,3).toInputStream()?.asRequestBody() ?: return false
                )
            )
        )
        if (result.msg != "success")
            return false
        return true
    }
}